/********************************************
* Copyrigt (C) rumi
* Module: View_UartCore.h
*********************************************/
#ifndef View_UartCore_H
#define View_UartCore_H

#include <QSerialPort>
#include <QSerialPortInfo>
#include <QThread>
#include <QByteArray>
#include <QMutex>
#include <QMutexLocker>
#include <QDebug>

class UartCore : public QObject {
    Q_OBJECT

public:
    UartCore();
    ~UartCore();
    
    bool openSerialPort(const QString &portName, int baudRate = 9600);
    void closeSerialPort();
    bool writeData(const QByteArray &data);
    QByteArray readData();

signals:
    void dataReceived(const QByteArray &data);  // A signal to receive the data

private:
    QSerialPort *serialPort;  // Uart object
    QThread *sendThread;      
    QThread *receiveThread;   

    void startReceiveThread();
    void startSendThread();

    void receiveData();
    void sendData();

    QMutex mutex;  
};

#endif
/********************************************
 * End of file
*********************************************/